﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WAD.Model;
using WAD.DAL;

namespace WAD.BLL
{
    public class UserBLL
    {
        /// <summary>
        /// 获取代理商的客户列表
        /// </summary>
        public PageData GetList_Agent(int agentId, string siteName, string userName, int id, string phone, string email,string version_id , int page, int pageSize)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(" agentid={0}", agentId);

            if (id > 0)
                sb.AppendFormat(" and id={0}", id);

            if (!string.IsNullOrEmpty(siteName))
                sb.AppendFormat(" and nick_name like '%{0}%'", QD.WX.Utill.Util.FilterSql(siteName));

            if (!string.IsNullOrEmpty(userName))
                sb.AppendFormat(" and name='{0}'", QD.WX.Utill.Util.FilterSql(userName));

            if (!string.IsNullOrEmpty(phone))
                sb.AppendFormat(" and phone='{0}'", QD.WX.Utill.Util.FilterSql(phone));

            if (!string.IsNullOrEmpty(email))
                sb.AppendFormat(" and email='{0}'", QD.WX.Utill.Util.FilterSql(email));

            if (!string.IsNullOrEmpty(version_id) && (!version_id.Equals("0")))
                sb.AppendFormat(" and version_id in({0})", QD.WX.Utill.Util.FilterSql(version_id));

            PageData dt = DAO.GetListPage("[id],name,nick_name,phone,email,date,version_id,end_date,'' as groupname", "id desc", page, pageSize, sb.ToString(), "[v_user_version]");
            for (int i = 0; i < dt.table.Rows.Count; i++)
            {
                if (dt.table.Rows[i]["version_id"] != DBNull.Value)
                    dt.table.Rows[i]["groupname"] = VersionBLL.GetVersion(Convert.ToInt32(dt.table.Rows[i]["version_id"]));
            }
            return dt;
        }
    }
}